package cn.zxf.note.note.review;

import cn.zxf.note.common.web.AbstractController;
import cn.zxf.note.note.review.dto.NoteReviewListDto;
import cn.zxf.note.note.review.dto.NoteReviewTodayListDto;
import com.github.zengxf.common.domain.SimpleResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ServerWebExchange;

import java.util.List;

@RestController
@RequestMapping("/api/note/review")
public class NoteReviewController extends AbstractController {

    @Autowired
    private NoteReviewService service;

    @GetMapping("find-list")
    public List<NoteReviewTodayListDto> findList(
            ServerWebExchange ex,
            @RequestParam String date,
            @RequestParam Integer status
    ) {
        return service.findList(super.curUserId(ex), date, status);
    }

    @GetMapping("find-not-review-recent-date")
    public SimpleResult findNotReviewRecentDate(ServerWebExchange ex) {
        String recentDate = service.findNotReviewRecentDate(super.curUserId(ex));
        return SimpleResult.OK
                .put("recent_date", recentDate);
    }

    @PutMapping("update-to-reviewed/{id}")
    public SimpleResult updateToReviewed(
            ServerWebExchange ex,
            @PathVariable Integer id
    ) {
        service.updateToReviewed(super.curUserId(ex), id);
        return SimpleResult.OK;
    }

    @PutMapping("update-to-not-reviewed/{id}")
    public SimpleResult updateToNotReviewed(
            ServerWebExchange ex,
            @PathVariable Integer id
    ) {
        service.updateToNotReviewed(super.curUserId(ex), id);
        return SimpleResult.OK;
    }

    @GetMapping("findList")
    public List<NoteReviewListDto> findList(
            ServerWebExchange ex,
            @RequestParam Integer noteId
    ) {
        return service.findList(super.curUserId(ex), noteId);
    }

    @PostMapping("resetReviewPlan")
    public SimpleResult resetReviewPlan(
            ServerWebExchange ex,
            @RequestParam Integer noteId
    ) {
        service.resetReviewPlan(super.curUserId(ex), noteId);
        return SimpleResult.OK;
    }

}
